package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.CouponDto;
import com.qf.commerce.common.vo.CouponVo;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠卷
 * 出品人:lsj
 * 1992915043@qq
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 模糊查询并分页
     * @param couponDto
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/page/list")
    public ResponseResult<PageInfo<CouponVo>>   getCouponPage(@RequestBody CouponDto couponDto, @RequestParam(defaultValue = "1") Integer page,
                                                              @RequestParam(defaultValue = "10") Integer size){
        try {
            return  ResponseResult.success(couponService.getCouponPage(couponDto,page,size));
        } catch (Exception e) {
         return    ResponseResult.query();
        }
    }

    /**
     * 批量删除
     * @param couponId
     * @return
     */
      @PutMapping("/del/couponId")
    public  ResponseResult<Integer>  deleteCouponByCouponId(@RequestBody List<Long> couponId){
          try {
              return  ResponseResult.success(couponService.deleteCouponByCouponId(couponId));
          } catch (Exception e) {
              return  ResponseResult.updateFailure();
          }
      }
      @PostMapping("/now/session")
      public  ResponseResult<Integer> CouponNowSession(@RequestBody CouponDto couponDto){
          try {
              return  ResponseResult.success(couponService.couponNowSession(couponDto));
          } catch (Exception e) {
              return  ResponseResult.add();
          }
      }
}
